function(txt2inc txt_file inc_dir out_inc_file)
    # The old script, left as a sample
	# get_fileName_component(fileName ${txt_file} NAME_WE)
	# get_fileName_component(fileExt ${txt_file} EXT)
    # make ext to upper case
    # string(TOUPPER ${fileExt} fileExt)

    # Extract the last level of directory name
	get_fileName_component(txt_path ${txt_file} PATH)
	get_fileName_component(txt_dir_name ${txt_path} NAME) 
	# make inc file name like srcDirName_simple.vs.inc
	get_fileName_component(fileName ${txt_file} NAME)
	set(gen_file "${inc_dir}/${txt_dir_name}/${fileName}.inc")
    if(${txt_file} IS_NEWER_THAN ${gen_file})
        # message("INFO: Generate inc file ${gen_file}")
        # 清空输出文件
        file(WRITE ${gen_file} "")
        # for c compatibility
        string(MAKE_C_IDENTIFIER "${txt_dir_name}.${fileName}" token)
        # read from file
        file(READ ${txt_file} content)
        # replace " to \"
        string(REGEX REPLACE "\"" "\\\\\"" content "${content}")
        # replace '\r'+'\n' to '\'+'n'+'"'+'\n'
        string(REGEX REPLACE "[\r\n]" "\\\\n\"\\\\\n\"" content "${content}")
        # insert the code for the definition of the variable and write file
        file(APPEND ${gen_file} "const char *${token} = \n\"${content}\";\n")
        # print gen message
        message(STATUS "INFO: translate ${fileName} -> ${gen_file}")
    endif()

	# output gen_file
	set(${out_inc_file} ${gen_file} PARENT_SCOPE)
endfunction()

function(txtDir2inc src_txt_dir dst_inc_dir)
    if(NOT EXISTS ${dst_inc_dir})
        # message warning
		message(WARNING "The directory does not exist! ${dst_inc_dir}!")
    else() # EXISTS ${dst_inc_dir}
   		# get all files in src_txt_dir
		file(GLOB srcFiles ${src_txt_dir}/*)
		# Process the files one by one
		foreach(srcfile ${srcFiles})
			# call glsl2inc gen one glslinc file
			txt2inc(${srcfile} ${dst_inc_dir} inc_file)
			# append glslinc file tu list glslinc_files
			# list(APPEND glslinc_files ${glslinc_file})
		endforeach()
    endif() # NOT EXISTS ${dst_inc_dir}
endfunction()

# init gen text to inc process, 
# set(src_txt_dir ${CMAKE_CURRENT_SOURCE_DIR}/embedSrc)
# set(dst_inc_dir ${CMAKE_CURRENT_BINARY_DIR}/embeddable)
function(text_gen_inc_init target src_txt_dir dst_inc_dir)
    # DEBUG info
    # message(STATUS "DEBUG: src_txt_dir=${src_txt_dir}")
    # message(STATUS "DEBUG: dst_inc_dir=${dst_inc_dir}")

    # make dst inc dir
    if(NOT EXISTS ${dst_inc_dir})
        file(MAKE_DIRECTORY ${dst_inc_dir})
        message(STATUS "md ${dst_inc_dir}")
    endif()

    # make genTarget binary dir
    get_filename_component(txt_dir_name ${src_txt_dir} NAME)
    set(gen_target_binary_dir ${CMAKE_CURRENT_BINARY_DIR}/${txt_dir_name}_txt2inc_build)
    # message(STATUS "DEBUG: gen_target_binary_dir=${gen_target_binary_dir}")
    if(NOT EXISTS ${gen_target_binary_dir})
        file(MAKE_DIRECTORY ${gen_target_binary_dir})
        message(STATUS "md ${gen_target_binary_dir}")
    endif()

    # build src files list and dst files list
    file(GLOB src_files "${src_txt_dir}/*")
    foreach(src_file ${src_files})
        txt2inc(${src_file} ${dst_inc_dir} dst_file)
        list(APPEND src_files_list, src_file)
        list(APPEND dst_files_list, dst_file)
    endforeach()

    # create text gen inc target
    set(gen_target_name ${target}_${txt_dir_name}_gen_inc)
    add_custom_target(
        ${gen_target_name}
        ALL
        COMMAND ${CMAKE_COMMAND} -S ${gen_target_binary_dir} -B ${gen_target_binary_dir}
        # -DGEN_TARGET_NAME:STRING=${gen_target_name} -DSRC_TXT_DIR:FILEPATH=${src_txt_dir} -DDST_INC_DIR:FILEPATH=${dst_inc_dir}
        WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
        COMMENT "do [${gen_target_name}]"
        SOURCES ${src_files_list}
        DEPENDS ${src_files_list}
        BYPRODUCTS ${dst_files_list}
        VE
    )
    message(STATUS "add custom target ${gen_target_name}")

    # config current target
    target_include_directories(${target} PRIVATE ${dst_inc_dir})
    target_sources(${target} PUBLIC ${dst_files_list})
    add_dependencies(${target} ${gen_target_name})

    # build CMakeLists.txt of text gen inc target
    set(gen_target_file ${gen_target_binary_dir}/CMakeLists.txt)
    if(NOT EXISTS ${gen_target_file})
        file(WRITE ${gen_target_file} )
        file(WRITE ${gen_target_file}
            "cmake_minimum_required(VERSION 3.5...3.30)\n"
            "project(do_${gen_target_name})\n"
            "include(${CMAKE_SOURCE_DIR}/cmake/gen/txt_gen_inc.cmake)\n"
            "txtDir2inc(${src_txt_dir} ${dst_inc_dir})\n" )
        message(STATUS "INFO: build ${gen_target_file}")
    endif()
endfunction() # text_gen_inc_init